package com.edu.exam.enums.curriculum.questionbank;

import java.math.BigDecimal;

/**
 * 指标等级枚举
 * 
 * 质量评估指标的等级定义
 * 
 * @author System
 * @version 1.0.0
 */
public enum MetricLevel {
    EXCELLENT("EXCELLENT", "优秀"),
    GOOD("GOOD", "良好"),
    FAIR("FAIR", "一般"),
    POOR("POOR", "较差");

    private final String code;
    private final String description;

    MetricLevel(String code, String description) {
        this.code = code;
        this.description = description;
    }

    public String getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    public static MetricLevel fromScore(BigDecimal score) {
        if (score == null) return FAIR;

        double scoreValue = score.doubleValue();
        if (scoreValue >= 90) return EXCELLENT;
        if (scoreValue >= 75) return GOOD;
        if (scoreValue >= 60) return FAIR;
        return POOR;
    }

    public static MetricLevel fromCode(String code) {
        for (MetricLevel level : values()) {
            if (level.getCode().equals(code)) {
                return level;
            }
        }
        return FAIR;
    }
}